package top.szhome.system.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.szhome.framework.core.tools.support.Resp;
import top.szhome.framework.core.tools.util.TreeUtil;
import top.szhome.framework.starter.db.support.SimpleController;
import top.szhome.system.convert.DeptConverter;
import top.szhome.system.dto.DeptDTO;
import top.szhome.system.entity.Dept;
import top.szhome.system.qry.DeptQry;
import top.szhome.system.service.DeptService;
import top.szhome.system.vo.DeptVO;

import java.util.List;

/**
 * 部门 接口实现
 *
 * @author 唐加利
 * @date 2023/07/31
 **/
@AllArgsConstructor
@RestController
@RequestMapping("/system/dept")
@Tag(name = "部门")
public class DeptController extends SimpleController<DeptService, DeptConverter, DeptQry, DeptDTO, Dept, DeptVO> {

    /**
     * 获取组织架构树
     *
     * @param query
     * @return
     */
    @Operation(summary = "组织机构树", description = "获取组织机构树")
    @GetMapping("tree")
    public Resp<List<DeptVO>> tree(DeptQry query) {
        List<DeptVO> depts = this.getBaseService().list(query);
        return Resp.success(TreeUtil.tree(depts));
    }

}
